<?php
if(!defined("BO_ROOT")){
    exit("NO BO");
}
/**
 * 验证字符类
 * @author yinhua
 *
 */
class verify {

	
	
	/**
	 * 验证邮箱
	 * @param unknown_type $email
	 */
	static function isEmail($email){
		return preg_match("/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/",$email);
	}
	
	/**
	 * 验证QQ
	 * @param unknown_type $qq
	 */
	static function isQq($qq){
		return preg_match("/^[1-9][0-9]{4,13}$/",$qq);
	}        
        
	
	/**
	 * 验证url
	 * @param unknown_type $url
	 */
	static function isUrl($url){
		return strlen($url)>10&&preg_match("/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/", $url);
	}
	
	/**
	 * 判断是否中文gbk的
	 * @param $s
	 * @param $length 最长多少，一个汉字两位
	 */
    static function isChinese($s,$length=0){
    	$where = $length?'{1,'.$length.'}':"+";
    	return preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u",$s);//utf-8的
//        return preg_match("/^[".chr(0xa1)."-".chr(0xff)."]$where$/",$s); 
    }
    
    /**
     * 判断用户名
     * @param type $username
     * @return type 
     */
    static function checkUsername($username){
        $username = strtolower($username);
        $length = strlen($username);
        if($length<3 || $length>20)
            return false;
        if(str_replace(array("'",'"'), "", $username)!=$username)
                return false;
        return true;
        //return preg_match('/^[a-za-z0-9'.chr(0xa1).'-'.chr(0xff).'_]{3,16}$/', $username);
    }
    
    /**
     * 判断手机
     * @param type $mobile
     * @return type 
     */
    static function checkMobile($mobile){
        return preg_match("/^13[0-9]{1}[0-9]{8}$|15[012389]{1}[0-9]{8}$|14[7]{1}[0-9]{8}$|18[2679]{1}[0-9]{8}$/",$mobile);
    }
    
}

?>